package com.julu.o2o.util;

import org.beetl.sql.core.ClasspathLoader;
import org.beetl.sql.core.ConnectionSource;
import org.beetl.sql.core.ConnectionSourceHelper;
import org.beetl.sql.core.DefaultNameConversion;
import org.beetl.sql.core.Interceptor;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.db.MySqlStyle;
import org.beetl.sql.ext.DebugInterceptor;


import com.julu.o2o.config.MysqlDBConfig;

/**
 * 
 * @author yangtonggan
 * @date 2016-6-11
 */
public class BeetlSqlDaoUtil {
	
	/**
	 * 用于获取以beetlsql为基础的Dao接口对应的实现者 
	 * @param c
	 * @return
	 */
	public static <Dao> Dao getDao(Class<Dao> c){
		ClasspathLoader loader = new ClasspathLoader("/sql/");
		ConnectionSource source = ConnectionSourceHelper.getSimple(MysqlDBConfig.driver, MysqlDBConfig.url, MysqlDBConfig.userName, MysqlDBConfig.password);
		SQLManager manager = new SQLManager(new MySqlStyle(), loader, source,new DefaultNameConversion(),new Interceptor[]{new DebugInterceptor()});
		Dao dao = manager.getMapper(c);
		return dao;
	}
	
}
